home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / SQLiteToGrid.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  28.9 KB  |  1,018 lines

  1. <?php
  2. // +------------------------------------------------------------------------+
  3. // | SQLiteToGrid                                                           |
  4. // +------------------------------------------------------------------------+
  5. // | Copyright (c) 2000-2003 FrΘdΘric HENNINOT                              |                           
  6. // | Email         fhenninot@freesurf.fr                                    |
  7. // | Licence       This code is released under GPL                          |
  8. // +------------------------------------------------------------------------+
  9.  
  10. /**
  11.  * PHP4 Grid Presentation Data with more feature.
  12.  * @package SQLiteManager
  13.  * @author FrΘdΘric HENNINOT <fhenninot@freesurf.fr>
  14.  * @version $Id: SQLiteToGrid.class.php,v 1.41 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.41 $
  15.  */
  16.  
  17. class SQLiteToGrid {
  18.     
  19.     /**
  20.     * Resource connection
  21.     * 
  22.     * @access private
  23.     * @var resource
  24.     */
  25.     var $SQLiteConnId;
  26.     
  27.     /**
  28.     * Original SQL Query
  29.     *
  30.     * @access private
  31.     * @var string
  32.     */
  33.     var $query;
  34.  
  35.     /**
  36.     * Count SQL Query
  37.     *
  38.     * @access private
  39.     * @var string
  40.     */
  41.     var $queryCount;
  42.  
  43.     /**
  44.     * SQL expression extract : between 'SELECT' and 'FROM'
  45.     *
  46.     * @access private
  47.     * @var string
  48.     */
  49.     var $listChamp;
  50.  
  51.     /**
  52.     * Default sort order
  53.     *
  54.     * @access private
  55.     * @var string
  56.     */
  57.     var $queryOrderDefault;
  58.  
  59.     /**
  60.     * Nombre d'enregistrement
  61.     *
  62.     * @access private
  63.     * @var int
  64.     */
  65.     var $nbRecordQuery;
  66.     
  67.     /**
  68.     * SQL expression sort var
  69.     *
  70.     * @access private
  71.     * @var string
  72.     */
  73.     var $order;
  74.  
  75.     /**
  76.     * SQL Init Sort column
  77.     * @access private
  78.     * @var int
  79.     */
  80.     var $orderInit;
  81.     
  82.     /**
  83.     * Number of record per page
  84.     *
  85.     * @access private
  86.     * @var string
  87.     */
  88.     var $recordPerPage;        
  89.     
  90.     /**
  91.     * Veritable requΩte executΘe
  92.     *
  93.     * @access private
  94.     * @var string
  95.     */
  96.     var $realQuery;    
  97.  
  98.     /**
  99.     * @access private
  100.     * @var array
  101.     * Column title label
  102.     */
  103.     var $title;    
  104.     
  105.     /**
  106.     * Identification table, to view many table in one page
  107.     * 
  108.     * @access private
  109.     * @var string
  110.     */
  111.     var $tabId;
  112.     
  113.     /**
  114.     * boolean array for Enable/Disable sort column
  115.     *
  116.     * @access private
  117.     * @var array
  118.     */
  119.     var $sort;
  120.     
  121.     /**
  122.      * Column title style.
  123.     * true : button for sort column
  124.     * false : hyperlink for sort column
  125.     *
  126.     * @access private
  127.     * @var bool
  128.     */
  129.     var $buttonStyle=true;
  130.     
  131.     /**
  132.     * Add var to hyperlink.
  133.     * Allow full domain
  134.     * example : 
  135.     * index.php?action=module&module=user
  136.     * ?action=module
  137.     *
  138.     * @access private
  139.     * @var string
  140.     */
  141.     var $getVar;
  142.     
  143.     /**
  144.     * data to print
  145.     *
  146.     * @access private
  147.     * @var array
  148.     */
  149.     var $data;
  150.     
  151.     /**
  152.     * tableau des styles 'CSS'.
  153.     * if empty, automatic value for TD, TABLE and BUTTON
  154.     *
  155.     * @access private
  156.     * @var array
  157.     */    
  158.     var $style;
  159.     
  160.     /**
  161.     * Alignement of the column result, without title
  162.     *
  163.     * @access private
  164.     * @var array
  165.     */
  166.     var $align;
  167.     
  168.     /**
  169.     * Formatage d'affichage de la colonne. Le resultat des autres colonne peuvent Ωtre utilisΘ dans une mΩme colonne mais sur la mΩme ligne
  170.     * a l'aide du masque #%num_colonne%#
  171.     *
  172.     * @access private
  173.     * @var array
  174.     */
  175.     var $format;
  176.     /**
  177.     * List the column to be hide
  178.     *
  179.     * @access private
  180.     * @var array
  181.     */
  182.     var $hide;
  183.     
  184.     /**
  185.     * List of the calculated column
  186.     *
  187.     * @access private
  188.     * @var array
  189.     */
  190.     var $calcColumn;
  191.     
  192.     /**
  193.     * Number of column in the result table and Title table
  194.     *
  195.     * @access private
  196.     * @var int
  197.     */    
  198.     var $nbColonne;
  199.     
  200.     /**
  201.     * table result width. also in px or %
  202.     *
  203.     * @access private
  204.     * @var int
  205.     */
  206.     var $width;
  207.     
  208.     /**
  209.     * view the navigation bar.
  210.     * Default : false
  211.     *
  212.     * @access private
  213.     * @var bool
  214.     */
  215.     var $navigate=false;
  216.     
  217.     /**
  218.     * theorical number of page
  219.     *
  220.     * @access private
  221.     * @var int
  222.     */
  223.     var $nbPage;
  224.     
  225.     /**
  226.     * Current page to view
  227.     *
  228.     * @access private
  229.     * @var int
  230.     */
  231.     var $pageStart;
  232.     
  233.     /**
  234.     * Information on navigate page
  235.     * @access public
  236.     * @var array
  237.     */
  238.     var $infoNav;
  239.     /**
  240.     * older column to sort.
  241.     * to know the sens
  242.     *
  243.     * @access private
  244.     * @var int
  245.     */
  246.     var $oldOrder;
  247.     
  248.     /**
  249.     * Determine the sort order
  250.     * 'ASC' or 'DESC'
  251.     *
  252.     * @access private
  253.     * @var string
  254.     */
  255.     var $orderSens;
  256.     
  257.     /**
  258.     * Buffer to send to the brother
  259.     *
  260.     * @access private
  261.     * @var string
  262.     */
  263.     var $out;
  264.     
  265.     /**
  266.     * Caption for table
  267.     *
  268.     * @access private
  269.     * @var array $tabCaption  array("align"=>, "content"=>)
  270.     */
  271.     var $tabCaption;
  272.     
  273.     /**
  274.     * Disable 'OnClick' javascript function on table
  275.     *
  276.     * @var boolean $onClick 
  277.     */
  278.     var $onClick;
  279.     
  280.     /**
  281.     * Class constructor    
  282.     *
  283.     * @access public
  284.     * @param resource $connId resource SQLite Connection
  285.     * @param string $query SQL query to display
  286.     * @param string $tabId table name for display many table with independante navigate
  287.     * @param bool $autoTitle if true the class determineless the column title
  288.     * @param int $nbRecord nb line view per page
  289.     * @param string $width width of the end table (px or %)
  290.     */
  291.     function SQLiteToGrid(&$connId, $query, $tabId='', $autoTitle=true, $nbRecord=10, $width=500){
  292.         if(is_resource($connId) || is_object($connId)) $this->SQLiteConnId = $connId;
  293.         if($tabId) $this->tabId = $tabId;
  294.         else $this->setTabId();
  295.         $this->_fromSession();
  296.         $posEnd = strrpos(trim($query), ';');
  297.         if($posEnd) $query = substr(trim($query), 0, $posEnd);
  298.         $this->query = $query;
  299.         $this->onClick = true;
  300.         $this->recordPerPage = $nbRecord;
  301.         $this->navigate = true;
  302.         $this->_parseQuery($autoTitle);
  303.         $this->_definePage();
  304.         if($width) $this->width = $width;
  305.         if(empty($this->tabId)) $this->setTabId();
  306.         $data = $this->_getRecord();
  307.         if(is_array($data)){
  308.             foreach($data as $ligne){
  309.                 if(empty($this->nbColonne)) {                    
  310.                     $this->nbColonne = count($ligne);
  311.                 } elseif(count($ligne)!=$this->nbColonne) {
  312.                     $this->_sendError($GLOBALS['traduct']->get(105));
  313.                     return;
  314.                 }
  315.             }
  316.             $this->data = $data;
  317.         } else {
  318.             $this->_sendError($GLOBALS['traduct']->get(106));
  319.         }
  320.         $this->_toSession();
  321.         return true;        
  322.     }    
  323.     
  324.     /**
  325.     * Affectation of an identification table
  326.     *
  327.     * @access public
  328.     * @param string $ident identification string
  329.     */
  330.     function setTabId($ident=''){
  331.         if(!empty($ident)) {            
  332.             $this->tabId = $GLOBALS['GridTabId'][] = $ident;
  333.         } else {
  334.             // Recherche du plus grand indice
  335.             $tabIndex = $GLOBALS['GridTabId'];
  336.             if(!is_array($tabIndex)) {                
  337.                 $this->tabId = $GLOBALS['GridTabId'][]='tab1';
  338.             } else {
  339.                 $max = 0;
  340.                 foreach($tabIndex as $value){
  341.                     if((substr($value, 0, 3) == 'tab') && (($num = substr($value, 3, strlen($value)-3))>$max)) $max = $num;
  342.                 }
  343.                 $this->tabId = $GLOBALS['GridTabId'][] = 'tab'.($max+1);
  344.             }
  345.         }
  346.         return;
  347.     }
  348.  
  349.     /**
  350.     * Set Table title
  351.     *
  352.     * @access public
  353.     * @param array $title tableau des titres du tableau
  354.     */
  355.     function setTitle($title){
  356.         if(is_array($title)) $this->title = $title;
  357.         if(empty($this->nbColonne)) $this->nbColonne = count($title);        
  358.     }
  359.     
  360.     /**
  361.     * Set Alignement for the data table. no the title
  362.     *
  363.     * @access public
  364.     * @param array $tabAlign String table to set teh column alignement
  365.     */
  366.     function setAlign($tabAlign){
  367.         if(is_array($tabAlign)){
  368.             if(count($tabAlign)!=$this->nbColonne) {
  369.                 $this->_sendError($GLOBALS['traduct']->get(107));
  370.             } else {
  371.                 foreach($tabAlign as $align) {
  372.                     if( ($align != 'left') && ($align != 'center') && ($align != 'right') ) {
  373.                         $this->_sendError($GLOBALS['traduct']->get(108));
  374.                         return;
  375.                     }                    
  376.                 }
  377.                 $this->align = $tabAlign;
  378.             }
  379.         } else {
  380.             $this->_sendError($GLOBALS['traduct']->get(109));
  381.         }
  382.     }
  383.  
  384.     /**
  385.     * Affecte un format d'affichage pour chaque colonne
  386.     *
  387.     * @access public
  388.     * @param array $tabFormat tableau de chaine par colonne
  389.     */
  390.     function setFormat($tabFormat){
  391.         if(is_array($tabFormat)){            
  392.             $this->format = $tabFormat;
  393.         } else {
  394.             $this->_sendError($GLOBALS['traduct']->get(110));
  395.         }
  396.     }
  397.     /**
  398.     * Set the GET var to add into the links
  399.     *
  400.     * @access public
  401.     * @param string $string example : "?action=module&module=user"
  402.     */
  403.     function setGetVars($string){
  404.         $this->getVar = $string;
  405.         return;
  406.     }
  407.     
  408.     /**
  409.     * Allow sortable column. default all column are sortable
  410.     *
  411.     * @access public
  412.     * @param array $tabSort : bool array true->column sortable ; false->column not sortable
  413.     */
  414.     function setSort($tabSort){
  415.         if(is_array($tabSort)){
  416.             if(count($tabSort)!=$this->nbColonne) {
  417.                 $this->_sendError($GLOBALS['traduct']->get(111));
  418.             } else {
  419.                 foreach($tabSort as $sort) {
  420.                     if( ($sort != 0) && ($sort != 1) ) {
  421.                         $this->_sendError($GLOBALS['traduct']->get(112));
  422.                         return;
  423.                     }                    
  424.                 }
  425.                 $this->sort = $tabSort;
  426.             }
  427.         } else {
  428.             $this->_sendError($GLOBALS['traduct']->get(113));
  429.         }
  430.     }
  431.     
  432.     /**
  433.     * Default sort action is with button style. If false -> sort action is hyperlinks
  434.     *
  435.     * @access public
  436.     * @param bool $button
  437.     */
  438.     function enableSortStyle($button = true){
  439.         if($button) $this->buttonStyle = true;
  440.         else $this->buttonStyle = false;
  441.         return;
  442.     }
  443.     
  444.     /**
  445.     * Disable Navigation Barre when is automatically set
  446.     *
  447.     * @access public
  448.     */
  449.     function disableNavBarre(){
  450.         $this->navigate = false;
  451.     }
  452.     
  453.     /**
  454.     * Allow result column to be hide
  455.     *
  456.     * @access public
  457.     * @param int $num column number. can it a bool array with true->column is hide ; false->column is show
  458.     */
  459.     function hideColumn($num){
  460.         if(is_array($num)) $this->hide = $num;
  461.         else $this->hide[$num] = true;
  462.     }
  463.     
  464.     /**
  465.     * Same as hideColumn() but to show column
  466.     *
  467.     * @access public
  468.     * @param int $num 
  469.     * @see hideColumn($num)    
  470.     */
  471.     function showColumn($num){
  472.         if(is_array($num)) $this->hide = $num;
  473.         else $this->hide[$num] = false;
  474.     }
  475.     
  476.     /**
  477.     * This method is to add calculate column. default the position is at end.
  478.     * The format string, is a template string where you can use all the column result.
  479.     * 
  480.     * @access public
  481.     * @param string $title The column title
  482.     * @param string $format The string to be parse to set the value. format is #%ColNum%#, replace by the column value
  483.     * @param string $align Set the data alignement
  484.     * @param int $pos position de la colonne calculΘe, si 999 alors α la fin par ordre de crΘation
  485.     */
  486.     function addCalcColumn($title, $format, $align, $pos=999){
  487.         if(!empty($title)){
  488.             if(!empty($format)){
  489.                 if(!is_array($this->calcColumn)) $numCalc = 0;
  490.                 else $numCalc = count($this->calcColumn-1);
  491.                 $this->calcColumn[$numCalc]['title']     = $title;
  492.                 $this->calcColumn[$numCalc]['format']     = $format;
  493.                 $this->calcColumn[$numCalc]['align']     = $align;
  494.                 $this->calcColumn[$numCalc]['position'] = $pos;
  495.             } else {
  496.                 $this->_sendError($GLOBALS['traduct']->get(114));
  497.             }
  498.         } else {
  499.             $this->_sendError($GLOBALS['traduct']->get(115));
  500.         }
  501.     }
  502.     
  503.     /**
  504.     * Build the table result and buffer behind show
  505.     *
  506.     * @access public
  507.     * @return string
  508.     */
  509.     function build(){
  510.         $out = '';
  511.         $out .= $this->_showHeader();
  512.         $out .= $this->_showTable();
  513.         if($this->navigate) $out .= $this->_showNavigate();
  514.         $out .= $this->_showFooter();
  515.         $this->out = $out;
  516.         return $out;
  517.     }
  518.     
  519.     /**
  520.     * Show the result
  521.     *
  522.     * @access public
  523.     */
  524.     function show(){
  525.         echo $this->out;
  526.         return;
  527.     }
  528.     
  529.     /**
  530.     * Send error message to brother
  531.     *
  532.     * @access public
  533.     * @param string $message Error message
  534.     */
  535.     function _sendError($message){        
  536.         echo '<table width="300" style="border: 2px solid red;">'."\n";
  537.         echo '<tr><td align="center"><span style="font-size: 16px; color: red;"></span><b>'.$GLOBALS['traduct']->get(9).'</b></span></td></tr>'."\n";
  538.         echo '<tr><td align="center"><span style="font-size: 14px, color: blue;"><b>'.$message.'</b></span></td></tr>'."\n";
  539.         echo '</table>';
  540.         return;
  541.     }
  542.     
  543.  
  544.     /**
  545.     * Build the header, use Table and Thead for the title row
  546.     *
  547.     * @access private
  548.     * @return string
  549.     */    
  550.     function _showHeader(){
  551.       $out = '<!-- SQLiteToGrid.class.php : _showHeader() -->'."\n";        
  552.         $out .=     "<div align=\"".$GLOBALS["QueryResultAlign"]."\">\n<table width=".$this->width." cellspacing=0 cellpadding=0 class=\"".$this->tabId."\">\n";
  553.         
  554.         if(isset($this->tabCaption) && !empty($this->tabCaption)) {
  555.             $out .= "<caption style=\"white-space: nowrap\" align=\"".$this->tabCaption["align"]."\">".$this->tabCaption["content"]."</caption>";
  556.         }
  557.         $out .= "\t<thead>\n\t\t<tr>\n";
  558.         if(empty($this->getVar)) $this->getVar = '?';
  559.         else $this->getVar .= '&';
  560.         if(!is_array($this->sort)) $sortDefault = true;
  561.         if (count($this->title))
  562.         while(list($index, $titleColonne) = each($this->title)) {
  563.             $linkCond = ((!isset($this->sort[$index]) && $sortDefault) || $this->sort[$index]);
  564.             $sort = '';
  565.             if(is_array($this->calcColumn)){
  566.                 foreach($this->calcColumn as $calcCol){
  567.                     if($calcCol['position'] == $index){
  568.                         if($this->buttonStyle) $out .= "\t\t\t<td class=\"".$this->tabId."\"><button class=\"button\" type=\"button\">".$calcCol["title"]."</button></td>\n";
  569.                         else $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\">".$calcCol["title"]."</td>\n";
  570.                     }
  571.                 }
  572.             }
  573.             if((isset($_GET["sort".$this->tabId]) && ($_GET["sort".$this->tabId] == $index)) || (isset($this->orderInit) && ($this->orderInit==$index))){
  574.                 if($this->orderSens == "ASC") $infoSort = ' <img src="'.IMG_ASC.'" border="0">';
  575.                 else $infoSort = ' <img src="'.IMG_DESC.'" border="0">';    
  576.             } else {
  577.                 $infoSort = "";
  578.             }
  579.             if(!is_array($this->hide) || (!isset($this->hide[$index]) || !$this->hide[$index])){
  580.                 $align=($infoSort)?'right':'center';
  581.                 if($this->buttonStyle){
  582.                     if($linkCond) $sort = " onClick=\"document.location='".$this->getVar."sort".$this->tabId."=".$index."'\"";
  583.                     $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\"><button class=\"button\" type=\"button\"".$sort." class=\"".$this->tabId."\">".$titleColonne.$infoSort."</button></td>\n";
  584.                 } else {
  585.                     if($linkCond) {
  586.                         $out .= "\t\t\t".'<td align="'.$align.'" class="'.$this->tabId.'" style="white-space: nowrap"><a href="'.$this->getVar.'sort'.$this->tabId."=".$index.'" class="'.$this->tabId.'" style="border: 0px">'.$titleColonne.$infoSort.'</a></td>'."\n";
  587.                     } else {
  588.                         $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\" style=\"white-space: nowrap\">".$titleColonne."</td>\n";
  589.                     }
  590.                 }
  591.             }
  592.         }
  593.         if(is_array($this->calcColumn)){
  594.             foreach($this->calcColumn as $calcCol){
  595.                     if(    isset($index) && ($calcCol["position"] > $index)){
  596.                         if($this->buttonStyle) $out .= "\t\t\t<td class=\"".$this->tabId."\"><button class=\"button\" type=\"button\">".$calcCol["title"]."</button></td>\n";
  597.                         else $out .= "\t\t\t<td align=\"center\" class=\"".$this->tabId."\">".$calcCol["title"]."</td>\n";
  598.                     }
  599.             }
  600.         }
  601.         $out .= "\t\t</tr>\n";
  602.         $out .= "\t</thead>\n";
  603.         return $out;
  604.     }
  605.     
  606.     /**
  607.     * Build the data table result
  608.     *
  609.     * @access private
  610.     * @return string
  611.     */
  612.     function _showTable(){
  613.       $out = '<!-- SQLiteToGrid.class.php : _showTable() -->'."\n";    
  614.         $pos = 0;
  615.         if(is_array($this->data))
  616.         foreach($this->data as $ligne){
  617.             if($pos % 2) $localBgColor = $GLOBALS['browseColor1'];
  618.             else $localBgColor = $GLOBALS['browseColor2'];
  619.             $out .=  "\t<tr     onMouseOver=\"setRowColor(this, $pos, 'over', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\" 
  620.                                 onMouseOut=\"setRowColor(this, $pos, 'out', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\"";
  621.             if($this->onClick) $out .= "                        onMouseDown=\"setRowColor(this, $pos, 'click', '".$localBgColor."', '".$GLOBALS["browseColorOver"]."', '".$GLOBALS["browseColorClick"]."')\"";
  622.             $out .= ">\n";
  623.             while(list($index, $value) = each($ligne)){
  624.                 if($GLOBALS["allHTML"]) $value = htmlentities($value, ENT_NOQUOTES, $GLOBALS['charset']);
  625.                 if(!$GLOBALS["allFullText"]){
  626.                     if(strlen($value)>PARTIAL_TEXT_SIZE) $value = substr($value, 0, PARTIAL_TEXT_SIZE).'...';
  627.                 }
  628.                 if($value=="") {
  629.                     if(isset($this->NullInfo[$this->title[$index]]) && ($this->NullInfo[$this->title[$index]]==0)) $value="<i>NULL</i>";
  630.                     else $value=" ";
  631.                 }
  632.                 if(is_array($this->calcColumn)) {
  633.                     foreach($this->calcColumn as $calcCol){
  634.                         if($calcCol['position'] == $index) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.((!empty($calcCol['align']))? 'align="'.$calcCol['align'].'"' : '' ).'style="white-space: nowrap" width="10%" class="'.$this->tabId.'">'.$this->_formatCalc($ligne, $calcCol['format'], $pos ).'</td>'."\n";
  635.                     }
  636.                 }                
  637.                 if(!is_array($this->hide) || !isset($this->hide[$index]) || !$this->hide[$index]) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.(($this->align[$index])? 'align="'.$this->align[$index].'"' : '' ).'style="white-space: nowrap" class="'.$this->tabId.'">'.((!empty($this->format[$index]))? $this->_formatCalc($ligne, $this->format[$index]) : $value ).'</td>'."\n";
  638.             }
  639.             if(is_array($this->calcColumn)) {
  640.                 foreach($this->calcColumn as $calcCol){
  641.                     if($calcCol["position"] > $this->nbColonne) $out .= "\t\t".'<td bgcolor="'.$localBgColor.'" '.((!empty($calcCol['align']))? 'align="'.$calcCol['align'].'"' : '' ).'style="white-space: nowrap" width="10%" class="'.$this->tabId.'">'.$this->_formatCalc($ligne, $calcCol['format'], $pos ).'</td>'."\n";
  642.                 }
  643.             }
  644.             $out .= "\t</tr>\n";
  645.             $pos++;
  646.         }
  647.         return $out;
  648.     }
  649.     
  650.     /**
  651.     * Build the table footer
  652.     *
  653.     * @access private
  654.     * @return string
  655.     */
  656.     function _showFooter(){
  657.         return "</table>\n</div>\n";
  658.     }
  659.     
  660.     /**
  661.     * Build the navigation bar, it use the Tfoot
  662.     *
  663.     * @access private
  664.     * @return string
  665.     */
  666.     function _showNavigate(){
  667.       $out = '<!-- SQLiteToGrid.class.php : _showNavigate() -->'."\n";    
  668.         $out .= "\t<tr class=\"navbarre\"><td colspan=\"".$this->_countVisibleColumn()."\" align=\"center\" class=\"".$this->tabId."\" style=\"white-space: nowrap\">\n";
  669.         if(NAV_TOP) $top = '<img src="'.NAV_TOP.'" border=0>';
  670.         else $top = '<<';
  671.         if(NAV_PREC) $prec = '<img src="'.NAV_PREC.'" border=0>';
  672.         else $prec = '<';
  673.         if(NAV_SUIV) $suiv = '<img src="'.NAV_SUIV.'" border=0>';
  674.         else $suiv = '>';
  675.         if(NAV_END) $end = '<img src="'.NAV_END.'" border=0>';
  676.         else $end = '>>';
  677.         if(isset($_GET['sort'.$this->tabId])) $linkSort = 'sort'.$this->tabId.'='.$_GET['sort'.$this->tabId].'&';
  678.         else $linkSort = '';
  679.         if($this->pageStart>1) {            
  680.             $top = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=1\">".$top."</a>";
  681.             $prec = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->pageStart - 1)."\">".$prec."</a>";
  682.         }
  683.         if($this->pageStart<$this->nbPage){
  684.             $suiv = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->pageStart + 1)."\">".$suiv."</a>";
  685.             $end = "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".($this->nbPage)."\">".$end."</a>";            
  686.         }
  687.         if($this->nbPage<NAV_NBLINK){
  688.             $startLink = 1;
  689.             $endLink = $this->nbPage;
  690.         } else {            
  691.             if(($this->pageStart<($this->nbPage - (int)(NAV_NBLINK/2))) && ($this->pageStart>(int)(NAV_NBLINK/2))) $startLink = $this->pageStart - ((int)(NAV_NBLINK/2));
  692.             elseif($this->pageStart>=($this->nbPage - (int)(NAV_NBLINK/2))) $startLink = $this->nbPage - (NAV_NBLINK-1);
  693.             else $startLink = 1;
  694.             if( ($startLink+NAV_NBLINK-1) > $this->nbPage) {                
  695.                 $startLink = $this->nbPage - NAV_NBLINK + 1;
  696.                 $endLink = $this->nbPage;
  697.             } else {
  698.                 $endLink = $startLink + (NAV_NBLINK-1);
  699.             }
  700.         }
  701.         $link = '';
  702.         for($i=$startLink ; $i<=$endLink ; $i++){
  703.             if($i == $this->pageStart) $link .= '<span style="font-size: 12px;">'.$i.'</span>';
  704.             else $link .= "<a href=\"".$this->getVar.$linkSort."page".$this->tabId."=".$i."\"><span style='font-size: 12px'>".$i."</span></a>";
  705.             if($i < $endLink) $link .= NAV_SEP;
  706.         }
  707.         $infoNav = "  ".$GLOBALS["traduct"]->get(136)." ".$this->infoNav["start"]."-".$this->infoNav["end"]."/".$this->infoNav["all"];
  708.         $out .= "<div><div style=\"float: left\">".$infoNav."</div>";
  709.         $out .= "<div style=\"float: center\">".$top.NAV_SEP.$prec.NAV_SEP.$link.NAV_SEP.$suiv.NAV_SEP.$end."</div></div>";
  710.         $out .= "\t</td></tr>\n";
  711.         return $out;
  712.     }
  713.     
  714.     /**
  715.     * Simple template methode to replace var value in the string format for the calc Column
  716.     *
  717.     * @access private
  718.     * @param array &$ligne reference on the ligne result table
  719.     * @param string $format template to work with    
  720.     * @return string
  721.     */
  722.     function _formatCalc(&$ligne, $format, $pos=""){
  723.         preg_match('/#%(.*)%#/', $format, $var);
  724.         while(isset($var[1])){    
  725.             if((substr($var[1],0,3)!='POS') && (substr($var[1],0,5)!='QUERY')){
  726.                 $format = str_replace('#%'.$var[1].'%#', $ligne[$var[1]], $format);
  727.             } elseif(substr($var[1],0,3)=='POS'){
  728.                 $format = str_replace('#%POS%#', $pos, $format);
  729.             } elseif(substr($var[1],0,5)=='QUERY'){
  730.                 $format = str_replace('#%QUERY%#', urlencode($this->getRealQuery()), $format);
  731.             }
  732.             preg_match('/#%(.*)%#/', $format, $var);
  733.         }
  734.         return $format;
  735.     }
  736.     
  737.     /**
  738.     * Method for calc paginate
  739.     *
  740.     * @access private
  741.     */
  742.     function _definePage(){
  743.         $nbRecord = $this->_countRecord();
  744.         $this->nbPage = ceil($nbRecord / $this->recordPerPage);
  745.         if(!isset($_GET['page'.$this->tabId])) $this->pageStart = 1;
  746.         else $this->pageStart = $_GET['page'.$this->tabId];
  747.         $this->indexStart = (($this->pageStart - 1) * $this->recordPerPage);
  748.         $this->infoNav['start'] = $this->indexStart;
  749.         $this->infoNav['end']    = $this->indexStart + $this->recordPerPage;
  750.         $this->infoNav['all']    = $nbRecord;
  751.         if($this->infoNav['end']>$nbRecord) $this->infoNav['end']=$nbRecord;
  752.     }
  753.     
  754.     /**
  755.     * Methode to set the order sens
  756.     *
  757.     * @access private
  758.     */
  759.     function _checkOrder(){
  760.         if(isset($_GET['sort'.$this->tabId]) && ($_GET['sort'.$this->tabId]==$this->oldOrder) && (!isset($_GET['page'.$this->tabId]))){
  761.             if($this->orderSens == 'ASC') $this->orderSens = 'DESC';
  762.             else $this->orderSens = 'ASC';
  763.         } elseif(!isset($_GET['page'.$this->tabId])){
  764.             $this->orderSens = 'ASC';
  765.         }
  766.     }
  767.  
  768.     /**
  769.     * retreive session data
  770.     *
  771.     * @access private
  772.     */
  773.     function _fromSession(){
  774.         if(session_is_registered('old_order'.$this->tabId) || !empty($_SESSION['old_order'.$this->tabId])){
  775.             $this->oldOrder = $_SESSION['old_order'.$this->tabId];
  776.         }
  777.         if(session_is_registered('order_sens'.$this->tabId) || !empty($_SESSION['order_sens'.$this->tabId])){
  778.             $this->orderSens = $_SESSION['order_sens'.$this->tabId];
  779.         }
  780.         return;
  781.     }    
  782.     
  783.     /**
  784.     * save session data
  785.     *
  786.     * @access private
  787.     */
  788.  
  789.     function _toSession(){
  790.         if(!session_is_registered('old_order'.$this->tabId)){
  791.             session_register('old_order'.$this->tabId);
  792.         }
  793.         if(!isset($oldOrder)) $oldOrder = '';
  794.         if(isset($_GET['sort'.$this->tabId])) $oldOrder = $_GET['sort'.$this->tabId];
  795.         elseif(isset($this->orderInit)) $oldOrder = $this->orderInit;
  796.         $_SESSION['old_order'.$this->tabId] = $oldOrder;
  797.         if(!session_is_registered('order_sens'.$this->tabId)){
  798.             session_register('order_sens'.$this->tabId);
  799.         }
  800.         $_SESSION['order_sens'.$this->tabId] = $this->orderSens;
  801.         return;
  802.     }
  803.     
  804.     /**
  805.     * Return the visible column number
  806.     *
  807.     * @access private
  808.     * @return int
  809.     */
  810.     function _countVisibleColumn(){
  811.         if(is_array($this->hide)) $nbHide = array_sum($this->hide); else $nbHide = 0;
  812.         if(is_array($this->calcColumn)) $nbCalc = count($this->calcColumn); else $nbCalc = 0;
  813.         return ($this->nbColonne - $nbHide + $nbCalc);
  814.     }
  815.  
  816.     /**
  817.     * Parsing Original Query for extract information    
  818.     *
  819.      * @access private
  820.     * @param boolean $autoTitle false: extract title from query, true: extract with sql command
  821.     */
  822.     function _parseQuery($autoTitle){
  823.         $this->query = ereg_replace('^select[[:space:]]', 'SELECT ', $this->query);
  824.         $this->query = ereg_replace('[[:space:]]distinct[[:space:]]', ' DISTINCT ', $this->query);
  825.         $this->query = ereg_replace('[[:space:]]as[[:space:]]', ' AS ', $this->query);
  826.         $this->query = ereg_replace('[[:space:]]from[[:space:]]', ' FROM ', $this->query);
  827.         $this->query = ereg_replace('[[:space:]]where[[:space:]]', ' WHERE ', $this->query);
  828.         $this->query = ereg_replace('[[:space:]]group[[:space:]]+by[[:space:]]', ' GROUP BY ', $this->query);
  829.         $this->query = ereg_replace('[[:space:]]having[[:space:]]', ' HAVING ', $this->query);
  830.         $this->query = ereg_replace('[[:space:]]order[[:space:]]+by[[:space:]]', ' ORDER BY ', $this->query);
  831.         $this->query = ereg_replace('[[:space:]]limit[[:space:]]', ' LIMIT ', $this->query);
  832.         if($autoTitle){
  833.             $queryCalc = $this->query;
  834.             $queryCalc = str_replace('[[:space:]]DISTINCT[[:space:]]', ' ', $queryCalc);
  835.             $queryCalc = eregi_replace("\t|\n", ' ', $queryCalc);
  836.             preg_match('/SELECT[[:space:]](.*)[[:space:]]FROM/', $queryCalc, $listChamp);
  837.             if(isset($listChamp[1])) $this->listChamp = $listChamp[1];
  838.             else $this->listChamp = '';
  839.             preg_match('/ORDER[[:space:]]+BY[[:space:]]+(.*)/', $this->query, $order);
  840.             if(isset($order[0])) $this->query = str_replace($order[0], '', $this->query);
  841.             if(isset($order[1]) && (eregi('asc', $order[1]) || eregi('desc', $order[1]))){
  842.                 preg_match('/[[:space:]]+(.*)/', trim($order[1]), $sens);
  843.                 $order[1] = trim(str_replace($sens, '', $order[1]));
  844.                 $this->queryOrderSensDefault = trim($sens[1]);                
  845.             }
  846.             if(isset($order[1])) $this->queryOrderDefault = str_replace('"', '', $order[1]);
  847.             /*
  848.             if((!eregi("\*", $this->listChamp)) && !eregi("PRAGMA|EXPLAIN", $this->query)){
  849.                 $stringChamp = $this->listChamp;
  850.                 while($startPar = strpos($stringChamp, "(")){
  851.                     $endPar = strpos($stringChamp, ")");
  852.                     $chainePar = substr($stringChamp, $startPar, ($endPar-$startPar)+1);
  853.                     $stringChamp = str_replace($chainePar, "", $stringChamp);
  854.                 }
  855.                 $this->listChamp = $stringChamp;            
  856.                 $listChamp = explode(",", $this->listChamp);
  857.                 foreach($listChamp as $champ){
  858.                     preg_match("/[[:space:]]AS[[:space:]](.*)/i", $champ, $surname);
  859.                     if(isset($surname[1]) && !empty($surname[1])) {    
  860.                         $surname[1] = ereg_replace("\"|'", "", $surname[1]);
  861.                         $tabTitle[] = trim($surname[1]);
  862.                     } else {
  863.                         preg_match("/\.(.*)/", $champ, $table);
  864.                         if(isset($table[1]) && !empty($table[1])) $tabTitle[] = $table[1];
  865.                         else $tabTitle[] = trim($champ);
  866.                     }
  867.                 }
  868.             } else {
  869.                 $tabTitle = $this->_fetchField();                
  870.             }
  871.             */
  872.             $tabTitle = $this->_fetchField();                
  873.             
  874.             $this->setTitle($tabTitle);
  875.         }
  876.         preg_match('/FROM[[:space:]]+(.*)/', $this->query, $from);
  877.         if(isset($from[1])) $this->queryCount = 'SELECT count(*) FROM '.$from[1];
  878.         else $this->queryCount = $this->query;
  879.         if(isset($_GET['sort'.$this->tabId])){
  880.             while(list($index, $name) = each($tabTitle)){
  881.                 if($index == $_GET['sort'.$this->tabId]) $this->order = $name;
  882.             }
  883.         } elseif(!empty($this->queryOrderDefault)) {
  884.             $this->order = $this->queryOrderDefault;
  885.             $this->orderInit = array_search(trim($this->order), $tabTitle);
  886.         }
  887.         $this->_checkOrder();
  888.         return;        
  889.     }
  890.     
  891.     /**
  892.     * retourne le nombre d'enregistrement
  893.     *
  894.     * @access public
  895.     * @return int
  896.     */
  897.     function getNbRecord(){
  898.         return $this->nbRecordQuery;
  899.     }
  900.  
  901.     /**
  902.     * retourne la requΩte executΘe
  903.     *
  904.     * @access public
  905.     * @return string
  906.     */
  907.     function getRealQuery(){
  908.         return $this->realQuery;
  909.     }
  910.     
  911.     /**
  912.     * Return the column name, when parsing query can't determine it
  913.     *
  914.     * @access private
  915.     * @return array
  916.     */
  917.     function _fetchField(){
  918.         if(eregi('^select', $this->query) && !eregi('limit', $this->query)) $queryLoc = $this->query.' LIMIT 0,1';
  919.         else $queryLoc = $this->query;
  920.         if($res = $this->SQLiteConnId->query($queryLoc)){
  921.             for($i=0 ; $i < $this->SQLiteConnId->num_fields() ; $i++){
  922.                 $title[] = $this->SQLiteConnId->field_name(null, $i);
  923.             }
  924.             if(isset($title)) return $title;
  925.             else return false;
  926.         }
  927.         return false;
  928.     }
  929.     
  930.     /**
  931.     * Return the original number of record    
  932.     *
  933.      * @access private
  934.     * @return int
  935.     */
  936.     function _countRecord(){
  937.         if(!isset($this->nbRecordQuery)){
  938.             if($this->SQLiteConnId->getVersion()==2) {
  939.                 $qCount = preg_match('/^\s*(UPDATE|DELETE|INSERT|ALTER|JOIN|GROUP|LIMIT|PRAGMA)\s/i', $this->query);
  940.             } else {
  941.                 $qCount = false;
  942.             }
  943.             if($qCount){
  944.                 if($this->SQLiteConnId->query($this->queryCount)){
  945.                     $this->nbRecordQuery = $this->SQLiteConnId->fetch_single();
  946.                 } else $this->_sendError($GLOBALS['traduct']->get(117));
  947.             } else {
  948.                 $tabResult = $this->SQLiteConnId->array_query($this->query);
  949.                 $this->nbRecordQuery = count($tabResult);
  950.             }            
  951.         }
  952.         return $this->nbRecordQuery;
  953.     }
  954.     
  955.     /**
  956.     * Return an array with the data to send    
  957.     *
  958.      * @access private
  959.     * @return array
  960.     */
  961.     function _getRecord(){
  962.         if(isset($GLOBALS['TableListImpact'])){
  963.             $tableList = explode(',', $GLOBALS['TableListImpact']);
  964.             if(count($tableList)>1) $withTableName = true;
  965.             else $withTableName = false;
  966.             foreach($tableList as $tableImpact){
  967.                 if(!empty($tableImpact) && !eregi('\.', $tableImpact)){
  968.                     $tempInfoTable = $this->SQLiteConnId->array_query('PRAGMA table_info('.brackets(trim($tableImpact)).');');
  969.                     if(is_array($tempInfoTable)){
  970.                         foreach($tempInfoTable as $infoTable) {
  971.                             if($withTableName) $this->NullInfo[trim($tableImpact).'.'.$infoTable['name']] = $infoTable['notnull'];
  972.                             else $this->NullInfo[$infoTable['name']] = $infoTable['notnull'];
  973.                         }
  974.                     }
  975.                 }
  976.             }
  977.         }
  978.         if(strpos(trim($this->order), ' ')) $order = '"'.$this->order.'"';
  979.         else $order = $this->order;
  980.         
  981.         $query = $this->query.(($this->order)? ' ORDER BY '.$order.' '.$this->orderSens : '' );
  982.         if(!eregi('pragma', $this->query) && !eregi('limit', $this->query)) $query .= ' LIMIT '.$this->indexStart.', '.$this->recordPerPage;
  983.  
  984.         if($this->SQLiteConnId->query($query)){
  985.             unset($tabRecord);
  986.             $tabRecord = array();
  987.             while($ligne = $this->SQLiteConnId->fetch_array(null, SQLITE_NUM)){
  988.                 $tabRecord[] = $ligne;
  989.             }                
  990.         }
  991.         $this->realQuery = $query;
  992.         return $tabRecord;
  993.     }    
  994.     
  995.     /**
  996.     * Add caption to table
  997.     *
  998.     * @access public
  999.     * @param string $alignement
  1000.     * @param string $content
  1001.     */
  1002.     function addCaption($align, $content){
  1003.         $this->tabCaption['align'] = $align;
  1004.         $this->tabCaption['content'] = $content;
  1005.     }
  1006.     
  1007.     /**
  1008.     * Disable 'onclick' javascript function on table
  1009.     *
  1010.     * @access public
  1011.     */
  1012.     function disableOnClick(){
  1013.         $this->onClick = false;
  1014.         return;
  1015.     }
  1016. }
  1017. ?>
  1018.